﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Marmat.Template.WinForm
{
    public class DocumentCommandPagination : IDocumentCommandPagination
    {
        private readonly IDefaultDocumentCommandPagination command;
        public DocumentCommandPagination()
        {
            this.command = Marmat.FrameWork.SystemCommand.GetService<IDefaultDocumentCommandPagination>();
            this.command.Command = this;
        }

        public virtual string Name { get; }

        public virtual string PrimaryName { get; }


        public virtual object Create(DataRow item)
        {
            return this.command.Create(item);
        }

        public virtual void Delete(DataRow item)
        {
            this.command.Delete(item);
        }

        public virtual DataTable FillSchema()
        {
            return this.command.FillSchema();
        }

        public virtual DataTable Load(string condition, int page, int top, string order, out int count)
        {
            return this.command.Load(condition, page, top, order, out count);
        }

        public virtual DataRow Load(object id)
        {
            return this.command.Load(id);
        }

        public virtual void Write(DataRow item)
        {
            this.command.Write(item);
        }
    }

    public class DocumentCommandPagination<Entity> : IDocumentCommandPagination<Entity>
    {
        private readonly IDefaultDocumentCommandPagination<Entity> command;
        public DocumentCommandPagination()
        {
            this.command = Marmat.FrameWork.SystemCommand.GetService<IDefaultDocumentCommandPagination<Entity>>();
            this.command.Command = this;
        }

        public virtual string Name { get; }

        public virtual string PrimaryName { get; }


        public virtual object Create(Entity item)
        {
            
            return this.command.Create(item);
        }

        public virtual void Delete(Entity item)
        {
            this.command.Delete(item);
        }

        public virtual Entity[] Load(string condition, int page, int top, string order, out int count)
        {
            return this.command.Load(condition, page, top, order, out count);
        }

        public virtual Entity Load(object id)
        {
            return this.command.Load(id);
        }

        public virtual void Write(Entity item)
        {
            this.command.Write(item);
        }
    }
}
